package com.googlecode.genie5day;

import android.util.Log;
import junit.framework.TestCase;
import net.sourceforge.zmanim.AstronomicalCalendar;
import net.sourceforge.zmanim.util.GeoLocation;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;

/**
 * Created by IntelliJ IDEA.
 * User: Paul
 * Date: Sep 18, 2010
 * Time: 11:02:49 PM
 * To change this template use File | Settings | File Templates.
 */
public class TextDisplayTest extends TestCase {
    public void test_display() throws Exception {
        ForecastParser parser = new ForecastParser();
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        System.out.println("cal day: " + cal.get(Calendar.DAY_OF_YEAR));
        Forecast forecast = parser.getForecast((Calendar) cal.clone());

        double latitude = 39.46;
        double longitude = -75.70;
        double elevation = 0;


        GeoLocation location = new GeoLocation("Middletown", latitude, longitude,
                elevation, TimeZone.getDefault());
        AstronomicalCalendar ac = new AstronomicalCalendar(location);
        System.out.println("sunrise: " + DateFormat.getInstance().format(ac.getSunrise()));
        System.out.println("sunset: " + DateFormat.getInstance().format(ac.getSunset()));


        // Note - This will ignore and minutes in the offset - that's ok
        int hourOffsetFromGMT = 12 + cal.getTimeZone().getRawOffset() / 3600000 + 1;
        int startingHour = hourOffsetFromGMT % 3;

        for (int currentHour = startingHour; currentHour < 24; currentHour += 3) {
            System.out.print("\t" + currentHour % 12);
        }
        System.out.println();

        SimpleDateFormat dayFmt = new SimpleDateFormat("E");
        for (int day = 0; day < 5; day++) {
            String dayLabel = dayFmt.format(cal.getTime());
            System.out.print(dayLabel);
            for (int currentHour = startingHour; currentHour < 24; currentHour += 3) {
                cal.set(Calendar.HOUR_OF_DAY, currentHour);
                cal.getTimeInMillis(); // recalculate the calendar
                ForecastDetail detail = forecast.getForecastDetail(cal);
                System.out.print("\t" + (detail == null ? "-" : detail.getTemp()));
                //+ "|" + hourF.getTemp()
                //        + "|" + hourF.getWindSpeed() + "/" + hourF.getWindDirection());
            }
            System.out.println();
            cal.add(Calendar.DAY_OF_YEAR, 1);
        }
    }

    // write a service to write hourly yr.no weather data to a database
    // with a common provider

}
